package com.ncp.servlet.news;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ncp.model.biz.news.*;
import com.ncp.model.entity.news.NewsBean;

public class NewsClServlet extends HttpServlet {

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		response.setContentType("text/html;charset=UTF-8");
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		String type=request.getParameter("type");
		if(type.equals("content")){
			String id=request.getParameter("id");
			NewsBean nb=new NewsManager().getNews(id);
			//System.out.println(nb.getTitle());
			request.setAttribute("nb", nb);
			request.getRequestDispatcher("pages/news/news.jsp").forward(request, response);
		}else if(type.equals("del")){
			String id=request.getParameter("id");
			boolean b=new NewsManager().delNews(id);
			//System.out.println("aaa"+id);
			if(b){
				//System.out.println("aaa");
				request.getRequestDispatcher("pages/admin/newslist.jsp").forward(request, response);
			}
		}else if(type.equals("fenye")){
			String pageNow=request.getParameter("pageNow");
			//把pageNow放入到request
			request.setAttribute("pageNow", pageNow);
			request.getRequestDispatcher("pages/admin/newslist.jsp").forward(request, response);
		}else if(type.equals("fenye1")){
			String pageNow=request.getParameter("pageNow");
			//把pageNow放入到request
			request.setAttribute("pageNow", pageNow);
			request.getRequestDispatcher("pages/news/newslist.jsp").forward(request, response);
		}
		else if(type.equals("pages")){
			String pageNow=request.getParameter("pageNow");
			//把pageNow放入到request
			request.setAttribute("pageNow", pageNow);
			request.getRequestDispatcher("pages/news/newslist.jsp").forward(request, response);
		}
	}
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=GBK");
		request.setCharacterEncoding("GBK");
		response.setCharacterEncoding("GBK");
		this.doPost(request, response);
	}

}
